﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Net.Sockets;
using System.Collections.Generic;
using System.Linq;

namespace MultiplayerTest.Communication
{
    public class TcpCommunicator
    {
        private Socket _socket;
        private List<Socket> _workerSockets;

        public TcpCommunicator()
        {
            _socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            _socket.Bind(new IPEndPoint(IPAddress.Any, 4502));
            _socket.Listen(4);
            _socket.BeginAccept(AcceptCallback, null);
        }

        private void AcceptCallback(IAsyncResult iasr)
        {
            Socket workerSocket = _socket.EndAccept(iasr);
            _workerSockets.Add(workerSocket);
            _socket.BeginAccept(AcceptCallback, null);
        }
    }
}
